<template>
	<view>
		<view class="list">
			<view class="acea-row row-middle row-between item border-b ">
				<view class="label label-m">
					品牌
				</view>
				<view class="acea-row row-middle row-right item-r">
					<Uselect class="input-r" v-model="dataform.brandId" :list="brandList" keyName="realname" keyId="id"
						@inChange="getBrandList" placeholder="请选择品牌" :name="brandId" />
				</view>
			</view>
			<view class="acea-row row-middle row-between item border-b">
				<view class="label label-m">
					品牌故事
				</view>
				<view class="textacea-box">
					<textarea placeholder="请填写品牌故事" v-model="dataform.brandStory" maxlength="-1"></textarea>
					<!-- <view class="num-text">
						{{description.length}}/{{maxLength}}
					</view> -->
				</view>
			</view>
		</view>
		<view class="submit-btn" @click="handleComfrim">
			完成
		</view>
	</view>
</template>

<script>
	import {
		getBrandStoryAddApi,
		getBrandListApi
	} from '@/api/brand/index.js'
	import Uselect from '../components/select.vue';
	export default {
		components: {
			Uselect
		},
		data() {
			return {
				brandList: [],
				dataform: {},
				brandId: ''
			}
		},
		onLoad(option) {
			this.dataform.brandId = option.brandId || null;
			this.brandId = option.brandName || null;
		},
		mounted() {
			this.getBrandList('');
		},
		methods: {
			//获取品牌列表
			async getBrandList(realname) {
				uni.showLoading({
					title: '加载中'
				});
				try {
					let res = await getBrandListApi({
						limit: 10,
						realname
					});
					this.brandList = res.data.list
				} catch (e) {
					console.log(e)
					//TODO handle the exception
				}
				uni.hideLoading()
			},
			async handleComfrim(){
				let that = this;
				if(!this.dataform.brandId) return that.$util.Tips({
					title:'请选择品牌'
				})
				if(!this.dataform.brandStory) return that.$util.Tips({
					title:'请输入品牌故事'
				})
				try{
					let res = await getBrandStoryAddApi(this.dataform);
					uni.navigateBack()
				}catch(e){
					//TODO handle the exception
				}
			}
		}
	}
</script>

<style lang="scss">
	@import '/static/css/releaseForm.css';
</style>